import {
    getMyovertime,
    getMyout,
    getMytrip,
    getMyattenddetail,
    getTypeList
    // getLeaveTypeList
} from '@/services/attendance/overtime';

export default {
    namespace: 'overtimeList',
    state: {
        overtimeData: [],
        tripData: [],
        outData: [],
        pagination: {
            current: 1,
            pageSize: 10,
            total: 0
        },
        typeList: [],
        overType: [],
        attenddetail: []
    },
    effects: {
        *fetchMyovertim({ payload, callback }, { put, call }) {
            const result = yield call(getMyovertime, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        overtimeData: result.data.rows,
                        pagination: {
                            current: result.data.pageNo,
                            pageSize: result.data.pageSize,
                            total: result.data.total
                        }
                    }
                });
            }
            if (callback) callback(result);
        },
        *fetchMyout({ payload, callback }, { put, call }) {
            const result = yield call(getMyout, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        outData: result.data.rows,
                        pagination: {
                            current: result.data.pageNo,
                            pageSize: result.data.pageSize,
                            total: result.data.total
                        }
                    }
                });
            }
            if (callback) callback(result);
        },
        *fetchMytrip({ payload, callback }, { put, call }) {
            const result = yield call(getMytrip, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        tripData: result.data.rows,
                        pagination: {
                            current: result.data.pageNo,
                            pageSize: result.data.pageSize,
                            total: result.data.total
                        }
                    }
                });
            }
            if (callback) callback(result);
        },
        *fetchMydetail({ payload }, { put, call }) {
            const result = yield call(getMyattenddetail, payload);
            if (result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        attenddetail: result.data.rows
                    }
                });
            }
        },
        *fetchTypeList({ payload, callback }, { put, call }) {
            const result = yield call(getTypeList, payload);
            if (result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        typeList: result.data
                    }
                });
                callback();
            }
        },
        *fetchOverType({ payload, callback }, { put, call }) {
            const result = yield call(getTypeList, payload);
            if (result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        overType: result.data
                    }
                });
                callback();
            }
        }
    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        },
        setPagination(state, { pagination }) {
            return {
                ...state,
                pagination
            };
        }
    }
};
